package cn.wcy.design_patterns.creationtype01.abstractfactory02.impl;

import cn.wcy.design_patterns.creationtype01.abstractfactory02.CacheService;
import cn.wcy.design_patterns.creationtype01.abstractfactory02.Factory;
import cn.wcy.design_patterns.creationtype01.abstractfactory02.matter.EGM;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class EGMCacheServiceImpl implements CacheService {

    private final EGM egm = new EGM();

    @Override
    public String get(String key) {
        return egm.gain(key);
    }

    @Override
    public void set(String key, String value) {
        egm.set(key, value);
    }

    @Override
    public void set(String key, String value, long timeout, TimeUnit timeUnit) {
        egm.setEx(key, value, timeout, timeUnit);
    }

    @Override
    public void del(String key) {
        egm.delete(key);
    }

    @Override
    public void afterPropertiesSet() {
        Factory.register(this.getClass().getSimpleName(), this);
    }
}
